﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy3_4_2_
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int wheels;
            float weight, maxLoad, oilPerKm;
            float nowLoad, runKm;

            // 从TextBox中获取输入
            wheels = int.Parse(textBox1.Text);
            weight = float.Parse(textBox2.Text);
            maxLoad = float.Parse(textBox3.Text);
            oilPerKm = float.Parse(textBox4.Text);
            nowLoad = float.Parse(textBox5.Text);
            runKm = float.Parse(textBox6.Text);

            // 创建卡车对象并设置参数
            Truck t = new Truck();
            t.SetVehicle(wheels, weight, maxLoad, oilPerKm);

            // 判断是否超重
            if (t.Overload(nowLoad))
            {
                MessageBox.Show("对不起！卡车已超重，请卸下一些货物。");
                textBox5.Text = "";
                textBox5.Focus();
            }
            else
            {
                MessageBox.Show($"卡车正在行驶中...\n\n现已耗油 {t.OilConsumption(runKm)} 升！");
                t.GetVehicle();
            }
        }
    }
}
